<template>
  <div class="rainDay">
    <div class="search">
      <h4>积水年总计</h4>
      <el-form size="small" :inline="true" :model="search" ref="searchForm">
        <el-form-item label="日期选择">
          <el-date-picker
            v-model="search.time"
            type="year"
            placeholder="选择日期"
            value-format="yyyy-MM-dd HH:mm:ss"
          ></el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button style="backgroundColor:#4E72C8;color:#fff" @click="getAddBook('searchForm')">查询</el-button>
          <el-button style="backgroundColor:#EAEAEA;color:#000" @click="empty('searchForm')">清空</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="charts">
      <year-chart v-if="flag" :chart-data="YearChartData"/>
      <div v-if="!flag" style="width:100%;height:480px"></div>
    </div>
  </div>
</template>
<script>
import { getTimeSeconds } from "../../../utils/myMethod";
import YearChart from "./YearChart";
export default {
  name: "YearPoint",
  components: {
    YearChart
  },
  data() {
    return {
      flag: false,
      YearChartData: {},
      search: {
        time: getTimeSeconds(new Date())
      }
    };
  },
  created() {
    this.getChartData();
  },
  methods: {
    // 获取年表数据
    getChartData() {
      let _this = this;
      let time = _this.search.time;
      _this.$http
        .get("dataPonding/findDatePonding", {
          params: {
            time: _this.search.time
          }
        })
        .then(res => {
          let pointNameArr = [];
          let pondingDepthArr = [];
          let resData = res.data;
          let resLength = res.data.length;
          for (var i = 0; i < resLength; i++) {
            pointNameArr.push(resData[i].deviceName);
            pondingDepthArr.push(resData[i].pondingDepth);
          }
          this.YearChartData.dataX = pointNameArr;
          this.YearChartData.dataY = pondingDepthArr;
          if (resLength > 0) {
            this.flag = true;
          }
        });
    },

    getAddBook() {
      this.getChartData();
    },
    empty() {
      this.search = {
        time: getTimeSeconds(new Date())
      };
      this.getChartData();
    }
  }
};
</script>
<style lang="less" scoped>
.rainDay {
  .charts {
    width: 100%;
    color: #ec1818f3;
    color: #29f017;
    color: #4040e2;
  }
  .searchTop {
    display: flex;
    justify-content: space-between;
  }
  .search {
    margin: 12px 0;
    display: flex;
    padding: 10px 0 0 10px;
  }
  h4 {
    text-align: center;
    padding: 0 10px;
    height: 32px;
    line-height: 32px;
    color: #4e72c8;
  }
}
</style>